package com.ruihu.admin.module.business.tasknode.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import com.ruihu.admin.module.business.tasknode.domain.dto.DefectTypeAddDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.DefectTypeDTO;
import com.ruihu.admin.module.business.tasknode.domain.dto.DefectTypeUpdateDTO;
import lombok.Data;

import java.util.Objects;

/**
 * [ 缺陷类型配置 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-09-04 10:46:11
 * @since JDK1.8
 */

@Data
@TableName("t_defect_type")
public class DefectTypeEntity extends BaseEntity{

    /**
     * 缺陷名称
     */
    private String defectName;

    /**
     * 乐观锁
     */
    private Integer revision;

    /**
     * 创建人
     */
    private Long createBy;


    /**
     * 更新人
     */
    private Long updateBy;


    /**
     * 描述
     */
    private String remark;


    public static DefectTypeEntity convertToDefectTypeEntity(DefectTypeAddDTO addDTO) {
        if (addDTO == null) {
            return null;
        }
        DefectTypeEntity entity = new DefectTypeEntity();
        entity.setRemark(addDTO.getRemark());
        entity.setDefectName(addDTO.getDefectName());
        return entity;
    }


    public static DefectTypeEntity convertToDefectTypeEntity(DefectTypeUpdateDTO updateDTO) {
        if (updateDTO == null) {
           return null;
        }

        DefectTypeEntity entity = new DefectTypeEntity();
        entity.setId(updateDTO.getId());
        entity.setDefectName(updateDTO.getDefectName());
        entity.setRemark(updateDTO.getRemark());
        return entity;
    }

    public static DefectTypeEntity convertToDefectTypeEntity(DefectTypeDTO dto) {
        if (dto == null) {
           return null;
        }

        DefectTypeEntity entity = new DefectTypeEntity();
        entity.setId(dto.getId());
        entity.setDefectName(dto.getDefectName());
        entity.setRevision(dto.getRevision());
        entity.setCreateBy(dto.getCreateBy());
        entity.setCreateTime(dto.getCreateTime());
        entity.setUpdateBy(dto.getUpdateBy());
        entity.setUpdateTime(dto.getUpdateTime());
        return entity;
    }

    public static DefectTypeEntity copyIgnoreNullAndEmpty(DefectTypeEntity sourceEntity, DefectTypeEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (Objects.nonNull(sourceEntity.getId())) {
           destEntity.setId(sourceEntity.getId());
        }
        if (StrUtil.isNotEmpty(sourceEntity.getDefectName())) {
           destEntity.setDefectName(sourceEntity.getDefectName());
        }
        if (Objects.nonNull(sourceEntity.getRevision())) {
           destEntity.setRevision(sourceEntity.getRevision());
        }
        if (Objects.nonNull(sourceEntity.getCreateBy())) {
           destEntity.setCreateBy(sourceEntity.getCreateBy());
        }
        if (Objects.nonNull(sourceEntity.getCreateTime())) {
           destEntity.setCreateTime(sourceEntity.getCreateTime());
        }
        if (Objects.nonNull(sourceEntity.getUpdateBy())) {
           destEntity.setUpdateBy(sourceEntity.getUpdateBy());
        }
        if (Objects.nonNull(sourceEntity.getUpdateTime())) {
           destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        }
        return destEntity;
    }
}
